var config = require('../../../../config/config.js');

var SystemConst = function(){
	this._FilePath = "./downloads/";
	this._SocketPort = null;
	this._Intranet = null;
};
SystemConst.prototype = {
	//文件下载地址
    get FilePath(){
    	if(this._FilePath == null && config.System != undefined && config.System != null){
    		this._FilePath = config.System.FilePath;
    	}
		return this._FilePath;
	},
	//Socket通信端口，如果要启用Socket通信，必须指定端口号，根据服务器开发端口号配置
	get SocketPort(){
		if(this._SocketPort == null && config.System != undefined && config.System != null){
    		this._SocketPort = config.System.SocketPort;
    	}
		return this._SocketPort;
	},
	//内网服务器，如果需要通过网关访问内部服务器，必须指定内部服务器地址，例如：http://127.0.0.1:3000
	get Intranet(){
		if(this._Intranet == null && config.System != undefined && config.System != null){
			if(config.System.Intranet != undefined && config.System.Intranet != null){
	    		var info = {
	    			HostName: null,
	    			Port: 80
	    		};
	    		if(config.System.Intranet.split(':').length > 2){	//带端口号的处理
	    			var lastPosition = config.System.Intranet.lastIndexOf(':');
	    			info.HostName = config.System.Intranet.substring(0, lastPosition);
	    			info.Port = config.System.Intranet.substring(lastPosition + 1, config.System.Intranet.length);
	    			this._Intranet = info;
	    		}
	    		else if(config.System.Intranet.split(':').length == 2){	//如果是80端口可以不录入端口号
	    			info.HostName = config.System.Intranet;
	    			this._Intranet = info;
	    		}
	    	}
    	}
		return this._Intranet;
	}
};

module.exports = new SystemConst();